<?php

namespace App\Models;

use App\Libraries\Common\CommonFun;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class RsConfig extends Model
{
    use HasFactory;

    public $timestamps=false;
    protected $fillable=['attr_name','attr_value','create_time'];
    public static function lists($page=0,$limit=10,$params=[]){
        $ary_where = array();
        $attr_name=data_get($params,'attr_name',false);

        if($attr_name){
            $ary_where[] = ['attr_name', 'like', '%'.$attr_name.'%'];
        }
        $query = self::where($ary_where);
        $count = $query->count();
        $data = $query->offset(CommonFun::getOffset($page, $limit))->limit($limit)->orderBy('id', 'desc')->get()->map(function (RsConfig $rebate) use ($count) {
            $rebate = $rebate->attributesToArray();

            return $rebate;
        })->toArray();

        return $data ? compact('count', 'data') : false;
    }
}
